from django.contrib import admin

# Register your models here.


from .models import TeacherProfile, Course, Scores, Students


class TeacherProfileAdmin(admin.ModelAdmin):
    # 定制哪些字段需要展示
    list_display = ('name', 'mobile', 'title', 'is_delete',)

    list_display_links = ('name',)  # 默认
    # sortable_by # 排序

    '''搜索框 ^, =, @, None=icontains'''
    search_fields = ['title', 'name']

    '''默认空值'''
    empty_value_display = 'NA'

    '''过滤选项'''
    list_filter = ('title', 'is_delete',)


class CourseAdmin(admin.ModelAdmin):
    # 定制哪些字段需要展示
    list_display = ('name', 'teacher__name', 'credit', 'xueshi')

    list_display_links = ('name',)  # 默认

    # sortable_by # 排序
    '''搜索框 ^, =, @, None=icontains'''
    search_fields = ['name', 'teacher__name']

    '''默认空值'''
    empty_value_display = 'NA'

    def teacher__name(self, obj):
        return obj.teacher.name

    teacher__name.short_description = '任课老师'


class ScoresAdmin(admin.ModelAdmin):
    # 定制哪些字段需要展示
    list_display = ('student__name', 'course__name', 'value')

    list_display_links = ('student__name',)  # 默认

    # sortable_by # 排序
    '''定义哪个字段可以编辑'''
    # list_editable = ('value',)

    '''搜索框 ^, =, @, None=icontains'''
    search_fields = ('student__name', 'course__name', 'value')

    '''默认空值'''
    empty_value_display = 'NA'

    def student__name(self, obj):
        return obj.student.name

    def course__name(self, obj):
        return obj.course.name

    course__name.short_description = '课程名称'
    student__name.short_description = '学生名称'


class StudentsAdmin(admin.ModelAdmin):
    list_display = ('name', 'grades', 'gender')

    '''搜索框 ^, =, @, None=icontains'''
    search_fields = ('name',)

    '''默认空值'''
    empty_value_display = 'NA'

    '''过滤选项'''
    list_filter = ('gender', 'grades',)

    pass


admin.site.register(TeacherProfile, TeacherProfileAdmin)
admin.site.register(Course, CourseAdmin)
admin.site.register(Scores, ScoresAdmin)
admin.site.register(Students, StudentsAdmin)

# admin.site
admin.AdminSite.site_header = "学生成绩管理系统首页"
admin.AdminSite.site_title = "学生成绩管理系统"
